package com.gitee.wsl.common.ui.ext

import androidx.compose.ui.geometry.MutableRect
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.toRect
import androidx.compose.ui.graphics.Canvas
import androidx.compose.ui.graphics.Paint
import androidx.compose.ui.graphics.withSave


fun Canvas.drawLine(x1: Float, y1: Float, x2: Float, y2: Float,paint: Paint)
         = drawLine(Offset(x1,y1),Offset(x2,y2),paint)


inline fun Canvas.inClip(
    left: Float,
    top: Float,
    right: Float,
    bottom: Float,
    crossinline block: () -> Unit,
) {
    withSave {
        clipRect(left, top, right, bottom)
        block()
    }
}

internal fun Canvas.drawRect(rect: MutableRect, paint: Paint) =
    drawRect(
        left = rect.left,
        top = rect.top,
        right = rect.right,
        bottom = rect.bottom,
        paint = paint
    )

internal fun Canvas.clipRect(rect: MutableRect) {
    clipRect(
        left = rect.left,
        top = rect.top,
        right = rect.right,
        bottom = rect.bottom,
    )
}


expect fun Canvas.saveLayer(rect : MutableRect, paint : Paint, flag : Int)

fun Canvas.saveLayer(rect: MutableRect, paint: Paint) = saveLayer(rect.toRect(), paint)